package com.itsm.controller;

import com.alibaba.fastjson.JSONObject;
import com.itsm.entity.User;
import com.itsm.service.UrlRequestService;
import com.itsm.service.UserService;
import com.itsm.service.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@Controller
public class LoginTest {

    @Autowired
    private UrlRequestService urlRequestService;

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/httpTest")
    @ResponseBody
    public Object getWeUser(HttpServletRequest request) throws Exception {


        request.getSession().setAttribute("userid","YinRuChenAi");
        request.getSession().setAttribute("alias","3537");
        request.getSession().setAttribute("name","吴宏升");

        return "ok";
    }

    @RequestMapping(value = "/httpTest44")
    @ResponseBody
    public Object getWeUser444(HttpServletRequest request) throws Exception {

        HashMap<String,String> param1 = new HashMap<>();
        param1.put("access_token", "9xK8SrPwzDYtIOcB5h1Af0RbiftkzChKOpTuEABn8n82_othRUCi8VUyDY8gfYMN3DBPPFtwee5tkF4cWtNW1O2Sk1LmPmSzpgooaYhug3uldHOImKpKYojqcjgGHg8ieXQ7uWiCcipu_-yK51E9Z__NiTOKBwX86CXnovCfOaupk6EfE08NquYk2oNYvxcapnbWYrCvTkuic5-ZspTkvQ");
        param1.put("userid", "YinRuChenAi");
        JSONObject re1 = (JSONObject) urlRequestService.requestGetUrl("https://qyapi.weixin.qq.com/cgi-bin/user/get",param1,null);
        JSONObject jsonObject1 = JSONObject.parseObject(re1.toString());
        String sup = jsonObject1.getString("direct_leader");
        List<String> sup1 = (List<String>) jsonObject1.get("direct_leader");
        String sa = sup1.get(0);
        return sa;
//        User user = userService.selectUser("YinRuChenAi");
//        user.setSuperior(sa);
//        Integer col = userService.updateUser(user);
//        return col;
    }

    @RequestMapping(value = "/httpTest1")
    @ResponseBody
    public Object getWeUser2(HttpServletRequest request) throws Exception {
        request.getSession().setAttribute("userid","11");
        request.getSession().setAttribute("alias","3537");
        request.getSession().setAttribute("name","规划图");

        return "ok";
    }

    @RequestMapping(value = "/operate")
    public Object operate()  {


        return "redirect:file:///D:/work/image/HMJY1-SOP-IT-001企业邮箱使用指引.pdf";
    }


    @RequestMapping(value="/login1" , method = RequestMethod.GET)
    public String login1(){
        return "redirect:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wwfbc200b28be3408d&redirect_uri=http://itservice.hmjy-ic.com:8098/getWeUser1&response_type=code&scope=snsapi_privateinfo&state=STATE&agentid=1000023#wechat_redirect";
    }







}
